package com.george.rocketmq.controller;

import com.george.rocketmq.entity.dto.Result;
import com.george.rocketmq.service.RocketMqProducerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @title: RocketMqController.java
 * @description: RocketMq控制器
 * @author: George
 * @date: 2023/3/24 12:03
 */
@Api(tags = "RocketMq消息队列相关控制器")
@RestController
@RequestMapping("/rocketmq")
public class RocketMqController {

    @Autowired
    private RocketMqProducerService rocketMqProducerService;

    @ApiOperation(value = "发送普通消息到MQ",notes = "发送普通消息到MQ")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "userName", value = "用户名", required = true, defaultValue = "张三")
    })
    @GetMapping("/send/{userName}")
    public void send(@PathVariable("userName") String userName) {
        String message = "{\"userName\":\" " + userName + "\"}";
        rocketMqProducerService.send(message);
    }

    @ApiOperation(value = "发送带tag的消息到MQ",notes = "发送带tag的消息到MQ")
    @GetMapping("/sendTag/{msg}")
    public Result<SendResult> sendTag(@PathVariable("msg") String msg) {
        SendResult sendResult = rocketMqProducerService.sendTagMsg(msg);
        return Result.successResult(sendResult);
    }

}
